package com.xcity.game.combat.buff;

import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;
import naga.x.game.template.Template;
import naga.x.game.template.TemplateException;
import naga.x.util.NumberUtils;

public class CombatBuffTemplate extends Template {

	protected String name;
	protected String icon;
	protected String desc;

	static TIntObjectMap<CombatBuffTemplate> buffs = new TIntObjectHashMap<CombatBuffTemplate>();

	private CombatBuffTemplate(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	@Override
	public void validate() throws TemplateException {
	}
	
	public static CombatBuffTemplate create(String icon) {
		int buffId = parseId(icon);
		CombatBuffTemplate buff = buffs.get(buffId);
		if (buff == null) {
			buff = new CombatBuffTemplate(buffId);
			buff.setIcon(icon);
			buffs.put(buffId, buff);
		}
		return buff;
	}
	
	static int parseId(String icon) {
		return NumberUtils.parseInt(icon.substring("buff_".length(), icon.length() - ".jpg".length()));
	}
	
//	public static void clear() {
//		buffs = null;
//	}
	
	public static CombatBuffTemplate find(int id) {
		return buffs.get(id);
	}

}
